package org.elsfs.cloud.common.mybatis.ext.sql.support.insert;



import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.util.lang.NamingCase;

import java.util.Collection;
import java.util.stream.Collectors;

/**
 * 标准实现
 *

 */
@RequiredArgsConstructor
public class StandardInsertIntoItem implements InsertIntoItem {

    /**
     * 插入表
     */
    private final String table;
    /**
     * 插入字段集合
     */
    private final Collection<String> insertFields;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return String.format(
            "INSERT INTO %s(%s)",
            this.table,
            this.insertFields.stream()
                .map(NamingCase::toUnderlineCase)
                .collect(Collectors.joining(", "))
        );
    }
}
